package swaggertest.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration  // 标记为 Spring 配置类
@EnableSwagger2  // 启用 Swagger 2
public class SwaggerConfig {

    @Bean
    public Docket apiDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                // 扫描 Controller 的包路径，根据你的项目调整
                .select()
                .apis(RequestHandlerSelectors.basePackage("controller"))
                .paths(PathSelectors.any())  // 匹配所有路径
                .build()
                .apiInfo(apiInfo());  // 配置文档基本信息
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("医院系统 API 文档")  // 文档标题
                .description("基于 Spring MVC 的科室模块接口文档")  // 文档描述
                .version("1.0")  // 版本号
                .build();
    }
}